package com.tao.base.model;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@Schema(description = "分页统一返回结果")
public class PageResult<T> implements Serializable {
    @Schema(description = "返回结果")
    private List<T> items;
    @Schema(description = "总条数")
    private long counts;
    @Schema(description = "当前页码")
    private long page;
    @Schema(description = "每页大小")
    private long pageSize;

    public static <V,P> PageResult<V> of(Page<P> po,List<V> voList){
        return PageResult
                .<V>builder()
                .page(po.getCurrent())
                .pageSize(po.getSize())
                .counts(po.getTotal())
                .items(voList)
                .build();
    }
}
